import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:mtf/app/net/HttpManger.dart';
import 'package:mtf/app/routes/app_pages.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class rechargeController extends GetxController{
  TextEditingController valueController = TextEditingController();
  var preAccount="0.00".obs;
  var _isCheckObs=true.obs;
  set CheckObs(value) => _isCheckObs.value = value;
  get CheckObs => _isCheckObs.value;

  void clickRecharge(){
    var money=valueController.text;
    if(money.isEmpty){
      SmartDialog.showToast("请输入买入金额");
    }else if(!CheckObs){
      SmartDialog.showToast("请选择支付方式");
    }else{
      Get.toNamed(Routes.UPLOAD_VOUCHER,arguments: {"money":money,"amount":preAccount.value});
    }

  }

  @override
  void onInit() {
    super.onInit();
    valueController.addListener(() {
      if(valueController.text.isNotEmpty){
        print('输入了：${valueController.text}');
        reqRechargeRule(valueController.text);
      }else{
        preAccount.value="0.00";
      }

    });
  }

  void reqRechargeRule(String money) async{
  var resp= await HttpManager.reqMoneyAccount(1, money);
  if(resp.isSuccessData()){
    preAccount.value=resp.data!.amount;
  }
  }
}
